//
//  ViewController.swift
//  popTableVC
//
//  Created by 李煜 on 2022/9/15.
//

import UIKit

class HomeVC: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()

    setupBtn()
  }

  func setupBtn() {
    let button = UIButton(type: .custom)
    button.addTarget(self, action: #selector(clickBtn(sender:)), for: .touchUpInside)
    button.setTitle("button", for: .normal)
    button.sizeToFit()
    button.center = view.center
    button.setTitleColor(.blue, for: .normal)
    button.backgroundColor = .orange
    view.addSubview(button)
  }

  @objc func clickBtn(sender: UIButton) {
    let pop = PopVC(barbuttonItem: nil, sourceView: sender, sourceRect: nil)
    pop.datas = ["蔬菜","水果","米面"]
    pop.delegate = self
    present(pop, animated: true)
  }
}

extension HomeVC: UIPopoverPresentationControllerDelegate, PopVCDelegate {
  func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
  }

  //  代理方法
  func select(viewController: UIViewController, index: Int) {
    print("点击了", index, "行")
  }
}
